package com.ivc.info.action;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.cs.framework.common.bo.Message;
import com.cs.framework.ui.bo.UIData;
import com.cs.framework.ui.web.UI;
import com.cs.framework.web.annotation.Action;
import com.cs.framework.web.annotation.Mapping;
import com.cs.framework.web.handler.Web;
import com.ivc.info.dto.base.ClientDto;
import com.ivc.info.service.ClientService;

/**
 * 客户
 * 
 * @author hedongzhou
 * 
 */
@Action("client")
public class ClientAction {

	private Log logger = LogFactory.getLog(getClass());

	@Resource
	private ClientService clientService;

	/**
	 * 进入客户管理页面
	 */
	@Mapping
	public void mainPage() {
		UI.returnPage("info_clt");
	}

	/**
	 * 查询客户
	 */
	@Mapping
	public Object query() {
		ClientDto clientDto = Web.bind(ClientDto.class);

		List<ClientDto> list = clientService.query(clientDto);
		int count = clientService.count(clientDto);

		return new UIData(list, count);
	}

	/**
	 * 新增客户
	 */
	@Mapping
	public Object save() {
		ClientDto clientDto = Web.bind(ClientDto.class);

		try {
			clientService.save(clientDto);

			return new Message("Y", "新增成功");
		} catch (Exception e) {
			logger.error(e.getMessage(), e);

			return new Message("N", e.getMessage());
		}
	}

	/**
	 * 修改客户
	 */
	@Mapping
	public Object update() {
		ClientDto clientDto = Web.bind(ClientDto.class);

		try {
			clientService.update(clientDto);

			return new Message("Y", "修改成功");
		} catch (Exception e) {
			logger.error(e.getMessage(), e);

			return new Message("N", e.getMessage());
		}
	}

}
